<template>
  <div>
    <el-form ref="pram" :model="pram" :rules="rules" label-width="120px" @submit.native.prevent>
      <el-form-item label="申领父母姓名" prop="parentsName">
        <el-input v-model="pram.parentsName" maxlength="20" placeholder="申领父母姓名"/>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input v-model="pram.gender" maxlength="20" placeholder="性别"/>
      </el-form-item>
      <el-form-item label="民族" prop="nation">
        <el-input v-model="pram.nation" maxlength="20" placeholder="民族"/>
      </el-form-item>
      <el-form-item label="公民身份证" prop="idCard">
        <el-input v-model.number="pram.idCard" placeholder="公民身份证"/>
      </el-form-item>
      <el-form-item label="工作单位" prop="workUnit">
        <el-input v-model.number="pram.workUnit" placeholder="工作单位"/>
      </el-form-item>
      <el-form-item label="户籍所在地" prop="registeredResidence">
        <el-input v-model.number="pram.registeredResidence" placeholder="户籍所在地"/>
      </el-form-item>
      <el-form-item label="现住址" prop="currentAddress">
        <el-input v-model.number="pram.currentAddress" placeholder="现住址"/>
      </el-form-item>
      <el-form-item label="申领起起始时间" prop="startingTimeOfApplication">
        <el-input v-model.number="pram.startingTimeOfApplication" placeholder="申领起起始时间"/>
      </el-form-item>
      <el-form-item label="停发时间" prop="stopSendingTime">
        <el-input v-model.number="pram.stopSendingTime" placeholder="停发时间"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="contactPhoneNumber">
        <el-input v-model.number="pram.contactPhoneNumber" placeholder="联系电话"/>
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input v-model.number="pram.remarks" placeholder="备注"/>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="handlerSubmit('pram')">确定</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Debounce } from '@/utils/validate'
import { randomString } from '@/utils/utils'

export default {
  components: {},
  props: {
    isCreate: {
      type: Number,
      required: true
    },
    editData: {
      type: Object,
      default: () => {
        return { rules: [] }
      }
    }
  },
  emits: ['educationFee', 'hideEditDialog'],
  data() {
    return {
      constants: this.$constants,
      pram: {
        id: null,
        parentsName: '',
        gender: '',
        nation: '',
        idCard: '',
        workUnit: '',
        registeredResidence: '',
        currentAddress: '',
        startingTimeOfApplication: '',
        stopSendingTime: '',
        contactPhoneNumber: '',
        remarks: ''
      },
      // rules: {
      //   parentsName: [{ required: true, message: '请填申领父母姓名', trigger: ['blur', 'change'] }],
      //   gender: [{ required: true, message: '请填性别', trigger: ['blur', 'change'] }],
      //   nation: [{ required: true, message: '请填民族', trigger: ['blur', 'change'] }],
      //   idCard: [{ required: true, message: '请填公民身份证', trigger: ['blur', 'change'] }],
      //   workUnit: [{ required: true, message: '请填工作单位', trigger: ['blur', 'change'] }],
      //   registeredResidence: [{ required: true, message: '请填户籍所在地', trigger: ['blur', 'change'] }],
      //   currentAddress: [{ required: true, message: '请填现住址', trigger: ['blur', 'change'] }],
      //   startingTimeOfApplication: [{ required: true, message: '请填申领起起始时间', trigger: ['blur', 'change'] }],
      //   stopSendingTime: [{ required: true, message: '请填停发时间', trigger: ['blur', 'change'] }],
      //   contactPhoneNumber: [{ required: true, message: '请填联系电话', trigger: ['blur', 'change'] }],
      // }
    }
  },
  mounted() {
    this.initEditData()
  },
  methods: {
    close() {
      this.$emit('hideEditDialog')
    },
    initEditData() {
      if (this.isCreate !== 1) {
        this.pram.id = randomString(32)
        return
      }
      const { id, parentsName, gender, nation, idCard , workUnit , registeredResidence , currentAddress , startingTimeOfApplication , stopSendingTime , contactPhoneNumber , remark } = this.editData
      this.pram.id = id
      this.pram.parentsName = parentsName
      this.pram.gender = gender
      this.pram.nation = nation
      this.pram.idCard = idCard
      this.pram.workUnit = workUnit
      this.pram.registeredResidence = registeredResidence
      this.pram.currentAddress = currentAddress
      this.pram.startingTimeOfApplication = startingTimeOfApplication
      this.pram.stopSendingTime = stopSendingTime
      this.pram.contactPhoneNumber = contactPhoneNumber
      this.pram.remark = remark
    },

    handlerSubmit: Debounce(function(form) {
      this.$refs[form].validate(valid => {
        if (!valid) return
        this.$emit('educationFee', this.pram)
        this.close()
      })
    })
  }
}
</script>

<style scoped>

</style>
